package com.tsingtao.springboot2.api.controller;

import com.tsingtao.springboot2.dto.Company;
import com.tsingtao.springboot2.dto.User;
import com.tsingtao.springboot2.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequestMapping("/freemarker")
public class FreemarkerController {

    @Autowired
    private CompanyService companyService;

    @GetMapping("/index")
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView("demo/index");
        User u1 = User.builder().name("u1").build();
        mv.addObject("user", u1);
        return mv;
    }

    @GetMapping("/company")
    public ModelAndView company() {
        ModelAndView mv = new ModelAndView("demo/company");
        List<Company> companyList = companyService.selectAll();
        mv.addObject("companyList", companyList);
        return mv;
    }

}
